import {getMDAppVersion} from "@/utils";

const state = {
  socket: null, // socket 对象
  scaleDeviceInfo: null,
  printers: [], // 所有的打印机
  currentPrinter: null, // 默认的打印机
  printerInterval: null, // 定时器
  currentPrinterStatus: 0, // 当前打印状态 -1打印异常 0待打印 1请求PDF接口 2正在打印 3打印完成
  scalesWeight: 0, // 电子秤的重量
  printerPDFType: 1,
  printerTestLoading: false,
  appCheckStatusAppStart: false, // 是否启动了APP （包含连接）
  appCheckStatusPrintersState: false, // 是否正常获取系统的打印机（只判断获取，不判断系统有多少个打印机）
  appCheckStatusScalesState: '', // 电子秤状态
  appCheckStatusAppVersion: null,  // 用于判断版本是否相同
  appVersion: getMDAppVersion(), // 软件的版本号
  // 秤状态
  scalesStateMapSearch: 'search',
  scalesStateMapConnected: 'connected',
  scalesStateMapDiscontented: 'discontented',
  scalesStateMapError: 'error',
  scalesStateMapTransform: 'transform',
  appStartDialog: false, // app启动检测
  isLinkApp: false, //是否已经链接硬件
}

const mutations = {
  SET_SOCKET: (state, socket) => {
    state.socket = socket
  },
  SET_SCALE_DEVICE_INFO: (state, scaleDeviceInfo) => {
    state.scaleDeviceInfo = scaleDeviceInfo
  },
  SET_PRINTERS: (state, printers) => {
    state.printers = printers
  },
  SET_CURRENT_PRINTER: (state, currentPrinter) => {
    state.currentPrinter = currentPrinter
  },
  SET_PRINTER_INTERVAL: (state, printerInterval) => {
    state.printerInterval = printerInterval
  },
  SET_CURRENT_PRINTER_STATUS: (state, currentPrinterStatus) => {
    state.currentPrinterStatus = currentPrinterStatus
  },
  SET_SCALES_WEIGHT: (state, scalesWeight) => {
    state.scalesWeight = scalesWeight
  },
  SET_PRINTER_PDF_TYPE: (state, printerPDFType) => {
    state.printerPDFType = printerPDFType
  },
  SET_PRINTER_TEST_LOADING: (state, printerTestLoading) => {
    state.printerTestLoading = printerTestLoading
  },
  SET_APP_CHECK_STATUS_APP_START: (state, appCheckStatusAppStart) => {
    state.appCheckStatusAppStart = appCheckStatusAppStart
  },
  SET_APP_CHECK_STATUS_PRINTERS_STATE: (state, appCheckStatusPrintersState) => {
    state.appCheckStatusPrintersState = appCheckStatusPrintersState
  },
  SET_APP_CHECK_STATUS_SCALES_STATE: (state, appCheckStatusScalesState) => {
    state.appCheckStatusScalesState = appCheckStatusScalesState
  },
  SET_APP_CHECK_STATUS_APP_VERSION: (state, appCheckStatusAppVersion) => {
    state.appCheckStatusAppVersion = appCheckStatusAppVersion
  },
  SET_APP_VERSION: (state, appVersion) => {
    state.appVersion = appVersion
  },
  SET_SCALES_STATE_MAP_SEARCH: (state, scalesStateMapSearch) => {
    state.scalesStateMapSearch = scalesStateMapSearch
  },
  SET_SCALES_STATE_MAP_CONNECTED: (state, scalesStateMapConnected) => {
    state.scalesStateMapConnected = scalesStateMapConnected
  },
  SET_SCALES_STATE_MAP_DISCONTENTED: (state, scalesStateMapDiscontented) => {
    state.scalesStateMapDiscontented = scalesStateMapDiscontented
  },
  SET_SCALES_STATE_MAP_ERROR: (state, scalesStateMapError) => {
    state.scalesStateMapError = scalesStateMapError
  },
  SET_SCALES_STATE_MAP_TRANSFORM: (state, scalesStateMapTransform) => {
    state.scalesStateMapTransform = scalesStateMapTransform
  },
  SET_APP_START_DIALOG: (state, appStartDialog) => {
    state.appStartDialog = appStartDialog
  },
  SET_IS_LINK_APP: (state, isLinkApp) => {
    state.isLinkApp = isLinkApp
  },
};

const actions = {
  setSocket({ commit }, socket) {
    commit('SET_SOCKET', socket);
  },
  setScaleDeviceInfo({ commit }, scaleDeviceInfo) {
    commit('SET_SCALE_DEVICE_INFO', scaleDeviceInfo);
  },
  setPrinters({ commit }, printers) {
    commit('SET_PRINTERS', printers);
  },
  setCurrentPrinter({ commit }, currentPrinter) {
    commit('SET_CURRENT_PRINTER', currentPrinter);
  },
  setPrinterInterval({ commit }, printerInterval) {
    commit('SET_PRINTER_INTERVAL', printerInterval);
  },
  setCurrentPrinterStatus({ commit }, currentPrinterStatus) {
    commit('SET_CURRENT_PRINTER_STATUS', currentPrinterStatus);
  },
  setScalesWeight({ commit }, scalesWeight) {
    commit('SET_SCALES_WEIGHT', scalesWeight);
  },
  setPrinterPDFType({ commit }, printerPDFType) {
    commit('SET_PRINTER_PDF_TYPE', printerPDFType);
  },
  setPrinterTestLoading({ commit }, printerTestLoading) {
    commit('SET_PRINTER_TEST_LOADING', printerTestLoading);
  },
  setAppCheckStatusAppStart({ commit }, appCheckStatusAppStart) {
    commit('SET_APP_CHECK_STATUS_APP_START', appCheckStatusAppStart);
  },
  setAppCheckStatusPrintersState({ commit }, appCheckStatusPrintersState) {
    commit('SET_APP_CHECK_STATUS_PRINTERS_STATE', appCheckStatusPrintersState);
  },
  setAppCheckStatusScalesState({ commit }, appCheckStatusScalesState) {
    commit('SET_APP_CHECK_STATUS_SCALES_STATE', appCheckStatusScalesState);
  },
  setAppCheckStatusAppVersion({ commit }, appCheckStatusAppVersion) {
    commit('SET_APP_CHECK_STATUS_APP_VERSION', appCheckStatusAppVersion);
  },
  setAppVersion({ commit }, appVersion) {
    commit('SET_APP_VERSION', appVersion);
  },
  setScalesStateMapSearch({ commit }, scalesStateMapSearch) {
    commit('SET_SCALES_STATE_MAP_SEARCH', scalesStateMapSearch);
  },
  setScalesStateMapConnected({ commit }, scalesStateMapConnected) {
    commit('SET_SCALES_STATE_MAP_CONNECTED', scalesStateMapConnected);
  },
  setScalesStateMapDiscontented({ commit }, scalesStateMapDiscontented) {
    commit('SET_SCALES_STATE_MAP_DISCONTENTED', scalesStateMapDiscontented);
  },
  setScalesStateMapError({ commit }, scalesStateMapError) {
    commit('SET_SCALES_STATE_MAP_ERROR', scalesStateMapError);
  },
  setScalesStateMapTransform({ commit }, scalesStateMapTransform) {
    commit('SET_SCALES_STATE_MAP_TRANSFORM', scalesStateMapTransform);
  },
  setAppStartDialog({ commit }, appStartDialog) {
    commit('SET_APP_START_DIALOG', appStartDialog);
  },
  setIsLinkApp({ commit }, isLinkApp) {
    commit('SET_IS_LINK_APP', isLinkApp);
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
